﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using IBuy.Entity;
namespace IBuy.Forms
{
    public partial class Chart : Form
    {
        public Chart()
        {
            InitializeComponent();
        }

        private void Chart_Load(object sender, EventArgs e)
        {
            this.cmbItemsName.SelectedIndex = 0;
            Histogram histogram = new Histogram();
            Drawing(histogram);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            /*
            int height = 420;
            int width = 530;
            Graphics g = this.panel1.CreateGraphics();
            Pen mypen = new Pen(new SolidBrush(Color.Red), 1);
            g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.DrawLine(mypen, new Point(0, this.panel1.Height), new Point(150, height - 200));

            int x = 0;
            for (int i = 0; i < 14; i++)
            {
                g.DrawLine(mypen, x, 80, x, 340);
                x = x + 40;
            }
            x = 0;
            String[] n = { "第一期", "第二期", "第三期", "第四期", "全年" };
            for (int i = 0; i < 5; i++)
            {
                g.DrawString(n[i].ToString(), new Font("", 8, FontStyle.Bold), Brushes.Blue, x, 348);
                x = x + 78;
            }
            String[] m = { "250", "225", "200", "175", "150", "125", "100" };
            int y = height;
            for (int i = 0; i < 7; i++)
            {
                g.DrawString(m[i].ToString(), new Font("", 8, FontStyle.Bold), Brushes.Blue, 25, y);
                y = y - 26;
            }
            **/
        }

        private void btnZF_Click(object sender, EventArgs e)
        {
            Histogram histogram = new Histogram();
            Drawing(histogram);
        }

        private void zedGraphGoods_Load(object sender, EventArgs e)
        {

        }

        private void Drawing(IBuy.Entity.Chart chart)
        {
            string itemName = "";
            string xItemName = "";
            string yItemName = "";
            string Title = "";
            if (this.cmbItemsName.Text.Equals("生产厂家"))
            {
                itemName = "CompanyName";
                Title = "生产厂家的统计";
                xItemName = "生产厂家";
                yItemName = "次数";
            }
            if (this.cmbItemsName.Text.Equals("价格"))
            {
                itemName = "Price";
                Title = "价格的统计";
                xItemName = "价格";
                yItemName = "次数";
            }
            if (this.cmbItemsName.Text.Equals("发货时间"))
            {
                itemName = "Delivery";
                Title = "发货时间的统计";
                xItemName = "发货时间";
                yItemName = "次数";
            }
            
            chart.Graph = this.zedGraphGoods;
            chart.ItemName = itemName;
            chart.Title = Title;
            chart.XItemName = xItemName;
            chart.YItemName = yItemName;
            chart.Draw();
            this.zedGraphGoods.Refresh();
        }

        private void btnQX_Click(object sender, EventArgs e)
        {
            
        }

        private void btnBZ_Click(object sender, EventArgs e)
        {
            PieChart chart = new PieChart();
            Drawing(chart);
        }
    }
}
